package com.beidu.lottery.call.errorcode;

import lombok.Getter;
import org.springframework.util.StringUtils;

/**
 * 接口状态码
 */
@Getter
public enum CommonCode {

    SUCCESS("000000", "成功"),
    ERROR("000001", "系统异常"),
    BUSY("000002", "系统繁忙，请稍候再试"),
    RATE_LIMITER("000003", "活动火热进行中，稍后再试"),
    FILE_NOT_EXIST("000004", "文件不存在"),
    QUERY_C_POINTS_FAIL("000005", "查询个人积分失败"),
    QUERY_B_POINTS_FAIL("000006", "查询平台积分失败"),
    UPDATE_C_POINTS_FAIL("000007", "积分更新失败"),
    REG_QUOTA_FULL("000008", "对不起，报名人数已满"),
    VOTE_TIMES_FULL("000009", "对不起，您的投票次数已用完"),
    ACTIVITY_NOT_EXIST("000010", "活动不存在"),
    OPTION_REFERENCED("000011", "选项已关联活动，请取消引用后再删除"),
    LOTTERY_TIMES_FULL("000012", "对不起，您的抽奖次数已用完"),
    LOTTERY_RECEIVE_INVALID("000013", "您未中奖，请先参加抽奖"),
    LOTTERY_RECEIVE_REPEAT("000014", "请勿重复提交领奖信息"),
    LOTTERY_CONFIG_PROBABILITY_ERROR("000015", "奖品池概率配置错误"),
    LOTTERY_CONFIG_PRIZE_ERROR("000016", "奖品池配置错误"),
    LOTTERY_INVENTORY_ADD_ERROR("000017", "操作库存失败"),
    USER_POINTS_ADD_ERROR("000018", "积分发放失败"),

    /**
     * jwt token 相关
     **/
    JWT_BASIC_INVALID("40000", "无效的基本身份验证令牌"),
    JWT_TOKEN_EXPIRED("40001", "会话超时，请重新登录"),
    JWT_SIGNATURE("40002", "不合法的token"),
    JWT_ILLEGAL_ARGUMENT("40003", "缺少token参数"),
    JWT_GEN_TOKEN_FAIL("40004", "生成token失败"),
    JWT_PARSER_TOKEN_FAIL("40005", "解析用户身份错误，请重新登录！"),
    JWT_USER_INVALID("40006", "用户名或密码错误"),
    JWT_USER_ENABLED("40007", "用户已经被禁用！"),
    JWT_OFFLINE("40008", "您已在另一个设备登录！"),
    JWT_CHECK_ACCOUNT("40009", "当前账户不存在！请重新输入"),
    JWT_THIRD_PARTY_INVALID("40010", "该第三方账号未绑定任何用户，请先登录或注册！"),
    TENANT_NOT_EXIST("40011", "缺少tenant参数"),
    JWT_TENANT_ENABLED("400012", "租户不存在或已经被禁用！"),

    ;

    /**
     * 错误类型码
     */
    private final String code;

    /**
     * 错误类型描述信息
     */
    private final String msg;

    CommonCode(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static CommonCode findByCode(String code) {
        if (StringUtils.isEmpty(code))
            return null;
        for (CommonCode commonCode : CommonCode.values()) {
            if (commonCode.getCode().equals(code))
                return commonCode;
        }
        return null;
    }

}
